package com.huxiu.utils;

import java.util.HashMap;
import java.util.Map;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import com.huxiu.APP;
import com.umeng.analytics.MobclickAgent;
import com.umeng.message.UmengNotificationClickHandler;
import com.umeng.message.entity.UMessage;

//使用自定义的NotificationHandler，来结合友盟统计处理消息通知
//参考http://bbs.umeng.com/thread-11112-1-1.html
public class CustomNotificationHandler extends UmengNotificationClickHandler{
	
	private static final String TAG = "dddddddd";
	
	@Override
	public void dismissNotification(Context context, UMessage msg) {
		super.dismissNotification(context, msg);
		Log.d(TAG, "dismissNotification");
		MobclickAgent.onEvent(context, "dismiss_notification");
	}
	
	@Override
	public void launchApp(Context context, UMessage msg) {

		super.launchApp(context, msg);
		Log.d(TAG, "launchApp");
		Map<String, String> map = new HashMap<String, String>();
		map.put("action", "launch_app");
		MobclickAgent.onEvent(context, "click_notification", map);
	}
	
	@Override
	public void openActivity(Context context, UMessage msg) {

		super.openActivity(context, msg);
		Log.d(TAG, "openActivity");
		Map<String, String> map = new HashMap<String, String>();
		map.put("action", "open_activity");
		MobclickAgent.onEvent(context, "click_notification", map);
		String id=msg.extra.get(Constants.PUSH_ID_KEY);
		if(msg.extra.get(Constants.PUSH_TYPE_KEY).equals(Constants.PUSH_TYPE_ARTICLE_VALUE)){
			Log.e(TAG,"111111111111");
			Utils.push_to_article(context,id);
		}else if(msg.extra.get(Constants.PUSH_TYPE_KEY).equals(Constants.PUSH_TYPE_HUATI_VLAUE)){
			Log.e(TAG,"22222222222");
			Utils.push_to_huati(context,id);
		}
	}
	
	@Override
	public void openUrl(Context context, UMessage msg) {
		super.openUrl(context, msg);
		Log.d(TAG, "openUrl");
		Map<String, String> map = new HashMap<String, String>();
		map.put("action", "open_url");
		MobclickAgent.onEvent(context, "click_notification", map);
	}
	
	@Override
	public void dealWithCustomAction(Context context, UMessage msg) {
		super.dealWithCustomAction(context, msg);
		Log.d(TAG, "dealWithCustomAction");
		Map<String, String> map = new HashMap<String, String>();
		map.put("action", "custom_actiaon");
		MobclickAgent.onEvent(context, "click_notification", map);
		String id=msg.extra.get(Constants.PUSH_ID_KEY);
		if(msg.extra.get(Constants.PUSH_TYPE_KEY).equals(Constants.PUSH_TYPE_ARTICLE_VALUE)){
			Log.e(TAG,"111111111111");
			Utils.push_to_article(context,id);
		}else if(msg.extra.get(Constants.PUSH_TYPE_KEY).equals(Constants.PUSH_TYPE_HUATI_VLAUE)){
			Log.e(TAG,"22222222222");
			Utils.push_to_huati(context,id);
		}
	}
	
	@Override
	public void autoUpdate(Context context, UMessage msg) {

		super.autoUpdate(context, msg);
		Log.d(TAG, "autoUpdate");
		Map<String, String> map = new HashMap<String, String>();
		map.put("action", "auto_update");
		MobclickAgent.onEvent(context, "click_notification", map);
	}

}
